Skip to content

Fix some time issues#854

Merged
ldecicco-USGS merged 22 commits intoDOI-USGS:developfrom
ldecicco-USGS:develop
Feb 10, 2026
Merged

Fix some time issues#854
ldecicco-USGS merged 22 commits intoDOI-USGS:developfrom
ldecicco-USGS:develop

Conversation

@ldecicco-USGS
Copy link
Collaborator

Should now allow this:

start <- "2025-10-01"
> end <- Sys.Date()
> dataRetrieval:::format_api_dates(c(start, end), date = TRUE)
[1] "2025-10-01/2026-02-02"

(which fixes #853 )

and this:

dataRetrieval:::format_api_dates(c("2010-01-01T00:00Z", "2010-01-01T05:00Z"))
[1] "2010-01-01T00:00:00Z/2010-01-01T05:00:00Z"

(which fixes #839 )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be changed to date?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think it should be changed to logical (because it tells the code whether or not to return a date or dateTime)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I meant the input is named "date" and it is logical, right?


if(length(datetime) == 1){
# If the user has "P" or the "/" we assume they know what they are doing
if(grepl("P", datetime, ignore.case = TRUE) |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, I tried this with a lowercase "p7d" and "p7D" and the API will not have it. I don't think there's necessarily anything you need to do here, just a random test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can plop a toupper in there, good to know!

Copy link
Collaborator

@ehinman ehinman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Approved. I particularly love this implementation:

start_end <- as.POSIXct(c("2021-01-01 12:15:00",
"2022-01-01 16:45"),
tz = "America/New_York")

dataRetrieval::format_api_dates(start_end)

Very nice.

A couple thoughts/suggestions that are optional: The function documentation for time, begin, and end don't go into detail on the range of dates that the functions will accept. Is this intentional?

In the Water Data APIs vignette, it does a few things with the time input, and there's a section that covers the time zone reference table, but it might be nice to show off using UTC offsets in an example, or the really lovely time zone example I highlight above, where you don't have to futz with offsets at all.

@ldecicco-USGS
Copy link
Collaborator Author

This looks good. Approved. I particularly love this implementation:

start_end <- as.POSIXct(c("2021-01-01 12:15:00", "2022-01-01 16:45"), tz = "America/New_York")

dataRetrieval::format_api_dates(start_end)

Very nice.

A couple thoughts/suggestions that are optional: The function documentation for time, begin, and end don't go into detail on the range of dates that the functions will accept. Is this intentional?

In the Water Data APIs vignette, it does a few things with the time input, and there's a section that covers the time zone reference table, but it might be nice to show off using UTC offsets in an example, or the really lovely time zone example I highlight above, where you don't have to futz with offsets at all.

I added a Detail section:

Details
You can also use a vector of length 2 for any time queries (such as time or last_modified). The first value is the starting date (or datetime), the second value is the ending date(or datetime). NA's within the vector indicate a half-bound date. For example, time = c("2024-01-01", NA) will return all data starting at 2024-01-01. time = c(NA, "2024-01-01") will return all data from the beginning of the timeseries until 2024-01-01. By default, time is assumed UTC, although time zone attributes will be accommodated. As an example, setting time = as.POSIXct(c("2021-01-01 12:00:00", "2021-01-01 12:00"), tz = "America/New_York") will request data that between noon and 2pm eastern time on 2021-01-01. All time values RETURNED from the service are UTC with the exception of daily data, which returns time values in local dates.

Let me know if you have any suggestions to fix that.

#' @param approval_status `r get_ogc_params("daily")$approval_status`
#' @param last_modified `r get_ogc_params("daily")$last_modified`
#'
#' See also Details below for more information.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't all have Details, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 49 below:

#' @inherit read_waterdata_continuous details

Brings the same "Detail" paragraph into other functions' help page

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh ok, neat. Thanks for sharing that.

#' the timeseries until 2024-01-01.
#' By default, time is assumed UTC, although time zone attributes
#' will be accommodated. As an example, setting \code{time = as.POSIXct(c("2021-01-01 12:00:00",
#' "2021-01-01 12:00"), tz = "America/New_York")} will request data that between
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2:00, not 12:00.

NEWS Outdated
* Added tests for read_waterdata_stats functions
* Updated next_req_url to allow paging through /statistics API output
* Added deprecate message to readNWISstat function.
* Added deprecate message to readNWISstat function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"deprecation"? I don't know why github isn't letting me direct edit things now. Maybe because I approved?

@ehinman
Copy link
Collaborator

ehinman commented Feb 10, 2026

Details looks good besides small typo that I made a comment about.

@ldecicco-USGS ldecicco-USGS merged commit a21564b into DOI-USGS:develop Feb 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants